# -*- coding: utf-8 -*-
import os
import sys
import os.path
import json
import uuid
import time
import random
import string
import hashlib
import urllib
import copy
from functools import partial
import logging
import pprint


import tornado
import tornado.web
import tornado.escape
import tornado.websocket
import tornado.httpclient
import tornado.gen



from datetime import datetime


from base import WebRequest
from base import WebSocket

import redis

logger = logging.getLogger(__name__)


class chat_mgr:
    r = redis.Redis(host='localhost',port=6379,db=0)

    def __init__(self):
        pass

    def add(self, group_id, v):
        self.r.sadd(group_id, v)
        pass

    def delete(self, group_id, v):
        self.r.srem(group_id, v)
        
        pass

    def members(self, group_id):
        return self.r.smembers(group_id)

    def join(self, key, group_id):
        self.r.set(key, group_id)

    def out(self, key):
        self.r.delete(key)

    def get(self, key):
        return self.r.get(key)


if __name__ == "__main__":

    test = chat_mgr()
    test.add("g1", "1")
    test.add("g1", "2")
    test.add("g1", "3")

    print test.get("g1")

    pass
